package com.simple.business.config.datasource;


import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.github.zuihou.database.datasource.BaseMybatisConfiguration;
import com.github.zuihou.database.properties.DatabaseProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author caojinzhou
 * @date 2022-11-17
 */
@Configuration
@Slf4j
@EnableConfigurationProperties({DatabaseProperties.class})
public class BusinessMybatisAutoConfiguration extends BaseMybatisConfiguration {

    public BusinessMybatisAutoConfiguration(DatabaseProperties databaseProperties) {
        super(databaseProperties);
    }

    /**
     * 新增乐观锁插件，分页插件要放到最后，文档写了
     *
     * @return DataScopeInterceptor
     */
    @Override
    protected List<InnerInterceptor> getPaginationBeforeInnerInterceptor() {
        List<InnerInterceptor> list = new ArrayList<>();
        list.add(new OptimisticLockerInnerInterceptor());
        return list;
    }
}
